package com.mytomcat.servlet;

import com.mytomcat.config.ServletConfig;

public abstract class MyHttpServlet {

    /**
     * 只会调用一次init()方法
     *
     * @param config
     * @throws Exception
     */
    public void init(ServletConfig config) throws Exception {
    }

    protected abstract void doGet(MyHttpServletRequest request, MyHttpServletResponse response) throws Exception;

    protected abstract void doPost(MyHttpServletRequest request, MyHttpServletResponse response) throws Exception;

    // 交给tomcat去调用
    public void service(MyHttpServletRequest request, MyHttpServletResponse response) throws Exception {
        if ("GET".equals(request.getMethod()))
            doGet(request, response);
        else if ("POST".equals(request.getMethod()))
            doPost(request, response);
    }
}
